package com.league.zjxn.main.home

import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.blankj.utilcode.util.ActivityUtils
import com.league.zjxn.R
import com.league.zjxn.jetpack.vmodel.HomeViewModel
import com.league.zjxn.main.adapter.HomeTrendTab1Adapter
import com.module.lemlin.owner.OwnerAbstractActivity
import com.module.lemlin.owner.OwnerViewModeActivity
import kotlinx.android.synthetic.main.activity_home_trend.*

class HomeTrendActivity : OwnerAbstractActivity() {

    companion object {
        fun open() {
            ActivityUtils.startActivity(HomeTrendActivity::class.java)
        }
    }

    //
    //类型[0=全部1=联盟新闻,2=通知公告,3=政策法规]

    private val mHomeTrendTab1Adapter = HomeTrendTab1Adapter()

    override val layoutResId: Int
        get() = R.layout.activity_home_trend

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = false, color = R.color.FF_004A96, view = flHomeTrendBar)
    }

    override fun initView() {
        rvHomeTrendTagBody.adapter = mHomeTrendTab1Adapter.apply {
            setNewInstance(mutableListOf("全部动态", "联盟新闻", "通知公告", "政策法规"))
        }.apply {
            setOnItemClickListener { _, _, i ->
                selectPosition = i
                vpHomeTrendBody.currentItem = i
            }
        }

        vpHomeTrendBody.adapter = object : FragmentStatePagerAdapter(
            supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            override fun getItem(position: Int): Fragment =
                HomeTrendFragment.newInstance(position)

            override fun getCount(): Int = 4

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {

            }
        }

        vpHomeTrendBody.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int, positionOffset: Float, positionOffsetPixels: Int
            ) = Unit

            override fun onPageSelected(position: Int) {
                mHomeTrendTab1Adapter.selectPosition = position
            }

            override fun onPageScrollStateChanged(state: Int) = Unit
        })
    }


}